<?php
// +----------------------------------------------------------------------
// | 终端撤改程序
// +----------------------------------------------------------------------
// | TongBaoChun <501468940@qq.com>
// +----------------------------------------------------------------------
// | 2015/06/23 'http://10.160.4.140/new/d/api/terminal/terminal_revoke.php',
// +----------------------------------------------------------------------
include_once("/var/www/html/new/com.inc.php");

$input  = file_get_contents('php://input');// 接收数据
$ac     = $GLOBALS['_ac'];
$pw     = $GLOBALS['_pw'];
$inside = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));


write_logs($input);
function write_logs($txt){
	$file = '/var/www/html/new/d/api/logs/terminal/terminal_revoke_data_'.date('Ym').'.txt';
	$fp = fopen($file,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,date("Y-m-d H:i:s").":".$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}


$data = json_decode($input, true);

if($data['Action']=='FinishMOD'){
	
	$orderid = $data['OrderID'];
	
	// 订单数据查询
	$resxml  = $inside->Order_Globle_Search("","","","","","","","","","","","", $orderid,"","","","","",1,1,0,1,"","","","","","","","","",0,1);
	$simxml  = simplexml_load_string($resxml);
	if((string)$simxml->Rec->UUpack_order!='0') exit('201|套票子票不允许撤改');
	
	
	$sql = "select id,dstatus,lid,tid,tnum,ordernum,dadmin from `uu_order_terminal_change` where ordernum='$orderid' order by id desc limit 1";
	$GLOBALS['le']->query($sql);
	if($GLOBALS['le']->fetch_assoc()) exit('200');
	
	$lid  = $data['Lid'];
	$tid  = $data['Tid'];
	$tnum = $data['Tnum'];
	$salerid  = $data['SalerID'];
	$terminal = $data['Terminal'];
	$member   = $data['Member'];
	$type     = $data['Tnum']==0 ? 1:0;
	
	$sql = "insert into uu_order_terminal_change (ordernum,terminal,salerid,lid,tid,stype,tnum,dstatus,reason,dadmin,stime) values ";
	$sql.= "('$orderid','$terminal','$salerid',$lid,$tid,$type,$tnum,0,'',$member,now())";
	if(!$GLOBALS['le']->query($sql)) exit('201|数据插入失败');
	
}





// CREATE TABLE `uu_order_terminal_change` (
  // `id` int(10) NOT NULL AUTO_INCREMENT,/*表id*/
  // `ordernum` char(20) NOT NULL,/*订单号*/
  // `terminal` int(6) unsigned NOT NULL,/*终端号*/
  // `salerid` char(6) NOT NULL,/*商家ID*/
  // `lid` int(6) unsigned NOT NULL,/*景点ID/大类ID*/
  // `tid` int(6) unsigned NOT NULL,/*门票ID/产品ID*/
  // `stype` tinyint(1) unsigned NOT NULL,/*申请类别0修改1撤销*/
  // `tnum` int(10) NOT NULL,/*0为撤销*/
  // `dstatus` tinyint(1) unsigned NOT NULL,/*状态0未操作1同意2已废弃*/
  // `reason` text NOT NULL,/*订单变动详细原因以及订单变动细节*/
  // `dadmin` varchar(20) NOT NULL,/*操作管理员ID*/
  // `stime` datetime DEFAULT NULL,/*申请提交时间*/
  // `dtime` datetime DEFAULT NULL,/*处理申请时间*/
  // PRIMARY KEY (`id`)
// ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='终端订单变动记录表';//